/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package su.samlib.informer.database.model;

import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author rikland
 */
@Entity
@Table(name = "user_authors")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "UserAuthors.findAll", query = "SELECT u FROM UserAuthors u"),
    @NamedQuery(name = "UserAuthors.findByAuthorId", query = "SELECT u FROM UserAuthors u WHERE u.userAuthorsPK.authorId = :authorId"),
    @NamedQuery(name = "UserAuthors.findByUserId", query = "SELECT u FROM UserAuthors u WHERE u.userAuthorsPK.userId = :userId"),
    @NamedQuery(name = "UserAuthors.findByAuthorBookLastUpdateCount", query = "SELECT u FROM UserAuthors u WHERE u.authorBookLastUpdateCount = :authorBookLastUpdateCount")})
public class UserAuthors implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected UserAuthorsPK userAuthorsPK;
    @Column(name = "author_book_last_update_count")
    private Integer authorBookLastUpdateCount;
    @JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User user;
    @JoinColumn(name = "author_id", referencedColumnName = "author_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Author author;

    public UserAuthors() {
    }

    public UserAuthors(UserAuthorsPK userAuthorsPK) {
        this.userAuthorsPK = userAuthorsPK;
    }

    public UserAuthors(int authorId, int userId) {
        this.userAuthorsPK = new UserAuthorsPK(authorId, userId);
    }

    public UserAuthorsPK getUserAuthorsPK() {
        return userAuthorsPK;
    }

    public void setUserAuthorsPK(UserAuthorsPK userAuthorsPK) {
        this.userAuthorsPK = userAuthorsPK;
    }

    public Integer getAuthorBookLastUpdateCount() {
        return authorBookLastUpdateCount;
    }

    public void setAuthorBookLastUpdateCount(Integer authorBookLastUpdateCount) {
        this.authorBookLastUpdateCount = authorBookLastUpdateCount;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Author getAuthor() {
        return author;
    }

    public void setAuthor(Author author) {
        this.author = author;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userAuthorsPK != null ? userAuthorsPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UserAuthors)) {
            return false;
        }
        UserAuthors other = (UserAuthors) object;
        if ((this.userAuthorsPK == null && other.userAuthorsPK != null) || (this.userAuthorsPK != null && !this.userAuthorsPK.equals(other.userAuthorsPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "su.samlib.informer.database.model.UserAuthors[ userAuthorsPK=" + userAuthorsPK + " ]";
    }
    
}
